package logic

import (
	"context"
	"errors"
	"user_srv/models/mysql"

	"user_srv/internal/svc"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type OrderViewLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewOrderViewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *OrderViewLogic {
	return &OrderViewLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *OrderViewLogic) OrderView(in *user.OrderViewRequest) (*user.OrderViewResponse, error) {
	// todo: add your logic here and delete this line
	order := mysql.Order{}
	err := order.OrderView(in.OrderId)
	if err != nil {
		logx.Info("查看订单信息失败")
		return nil, errors.New("查看订单信息失败")
	}

	return &user.OrderViewResponse{
		OrderSn:     order.OrderSn,
		PayType:     order.PayType,
		PayTime:     order.PayTime,
		Amount:      order.Amount,
		OrderStatus: order.OrderStatus,
	}, nil
}
